import request from 'src/axios'

/**
 * @description 上传文件
 * @param { FormData } data 上传参数
 * @returns Promise
 */
 export const uploadFile = (data: FormData) => {
  return request({
    url: '/file/info/upload',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

/**
 * @description 下载文件
 * @param { String } id 文件ID
 * @returns Promise
 */
 export const downloadFile = (id: string) => {
  return request({
    url: `/file/info/download/${id}`,
    method: 'get',
    responseType: 'blob'
  })
}

/**
 * @description 分页查询附件
 * @param { Object } params 查询参数
 * @returns Promise
 */
 export const pageAnnex = (params: object) => {
  return request.get('/file/annex/page', { params })
}

/**
 * @description 根据业务查询附件
 * @param { String } businessId 业务主键
 * @returns Promise
 */
 export const listAnnex = (businessId: string) => {
  return request.get('/file/annex/business', { params: { businessId } })
}

/**
 * @description 删除附件
 * @param { Array<string> } data 主键数组
 * @returns Promise
 */
 export const saveAnnex = (data: Array<string>) => {
  return request.post('/file/annex/batch/save', data)
}

/**
 * @description 删除附件
 * @param { Array<string> } ids 主键数组
 * @returns Promise
 */
export const deleteAnnex = (ids: Array<string>) => {
  return request.delete('/file/annex', { data: ids })
}
